home *** CD-ROM | disk | FTP | other *** search
/ Aminet 40 / Aminet 40 (2000)(Schatztruhe)[!][Dec 2000].iso / Aminet / game / shoot / ADoomPPC_src.lha / ADoomPPC_src / amiga_system.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-09-18  |  7.7 KB  |  344 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. #include <string.h>
  5. #include <stdarg.h>
  6. #include <time.h>
  7. #if defined(WARPUP) && !defined(__VBCC__)
  8. #include <sys/time.h>
  9. #endif
  10.  
  11. #include <exec/exec.h>
  12. #include <dos/dos.h>
  13. #include <dos/dosextens.h>
  14. #include <graphics/gfx.h>
  15. #include <graphics/gfxbase.h>
  16. #include <intuition/intuition.h>
  17. #include <intuition/intuitionbase.h>
  18. #include <proto/exec.h>
  19. #include <proto/utility.h>
  20.  
  21. //#include <powerup/clib/ppc_protos.h>
  22.  
  23. #ifdef WARPUP
  24. #include <clib/powerpc_protos.h>
  25. #endif
  26.  
  27. #include "doomdef.h"
  28. #include "m_misc.h"
  29. #include "i_system.h"
  30. #include "i_video.h"
  31. #include "i_sound.h"
  32.  
  33. #include "d_net.h"
  34. #include "g_game.h"
  35. #include "m_argv.h"
  36.  
  37. extern void ppctimer (unsigned int *time);
  38. extern double tb_scale_lo;
  39. extern double tb_scale_hi;
  40.  
  41. extern byte *vid_mem;
  42.  
  43. void amiga_getevents (void);
  44.  
  45. #define MIN_ZONESIZE  (2*1024*1024)
  46. #define MAX_ZONESIZE  (6*1024*1024)
  47.  
  48. /**********************************************************************/
  49.  
  50. extern struct ExecBase *SysBase;
  51. extern struct DosLibrary *DOSBase;
  52. //extern struct Library *UtilityBase;
  53. struct GfxBase *GfxBase = NULL;
  54. struct IntuitionBase *IntuitionBase = NULL;
  55.  
  56. /**********************************************************************/
  57. // Called by DoomMain.
  58. void I_Init (void)
  59. {
  60.   if ((GfxBase = (struct GfxBase *) OpenLibrary ("graphics.library", 39)) == NULL)
  61.     I_Error ("OpenLibrary(""graphics.library"", 39) failed");
  62.   if ((IntuitionBase = (struct IntuitionBase *) OpenLibrary ("intuition.library", 39)) == NULL)
  63.     I_Error ("OpenLibrary(""intuition.library"", 39) failed");
  64.  
  65.   I_InitSound ();
  66.   I_InitMusic ();
  67.   //  I_InitGraphics ();
  68. }
  69.  
  70. /**********************************************************************/
  71. // Called by startup code
  72. // to get the ammount of memory to malloc
  73. // for the zone management.
  74. byte*    I_ZoneBase (int *size)
  75. {
  76.   byte *zone;
  77.   ULONG memfree, largest;
  78.   int p;
  79.  
  80.   memfree = AvailMem (MEMF_FAST);
  81.   largest = AvailMem (MEMF_FAST | MEMF_LARGEST);
  82.   printf ("Memfree = %ld, largest = %ld\n", memfree, largest);
  83.  
  84.   p = M_CheckParm ("-heapsize");
  85.   if (p && p < myargc - 1) {
  86.  
  87.     *size = 1024 * atoi (myargv[p+1]);
  88.  
  89.   } else {
  90.  
  91.     if (largest > MAX_ZONESIZE + 65536 &&
  92.         memfree > MAX_ZONESIZE + (2 * 1024 * 1024))
  93.       *size = MAX_ZONESIZE;
  94.     else if (memfree < largest + (2 * 1024 * 1024))
  95.       *size = memfree - (2 * 1024 * 1024) - 65536;
  96.     else
  97.       *size = largest - 65536;
  98.  
  99.     if (*size < MIN_ZONESIZE)
  100.       I_Error ("Unable to allocate at least %d fastmem for zone management\n"
  101.                "while leaving 2Mb fastmem free\n"
  102.                "Fastmem free = %d, largest block = %d",
  103.                MIN_ZONESIZE, memfree, largest);
  104.   }
  105.  
  106.   if ((zone = (byte *)malloc(*size)) == NULL)
  107.     I_Error ("malloc() %d bytes for zone management failed", *size);
  108.  
  109.   printf ("I_ZoneBase(): Allocated %d bytes for zone management\n", *size);
  110.  
  111.   return zone;
  112. }
  113.  
  114. /**********************************************************************/
  115. // Called by D_DoomLoop,
  116. // returns current time in tics.
  117. int I_GetTime (void)
  118. {
  119.   unsigned int clock[2];
  120.   double currtics;
  121.   static double basetics=0.0;
  122.  
  123.   ppctimer (clock);
  124.   if (basetics == 0.0)
  125.     basetics = ((double) clock[0])*tb_scale_hi + ((double) clock[1])/tb_scale_lo;
  126.  
  127.   currtics = ((double) clock[0])*tb_scale_hi + ((double) clock[1])/tb_scale_lo;
  128.   return (int) (currtics-basetics);
  129. }
  130.  
  131. /**********************************************************************/
  132. //
  133. // Called by D_DoomLoop,
  134. // called before processing any tics in a frame
  135. // (just after displaying a frame).
  136. // Time consuming syncronous operations
  137. // are performed here (joystick reading).
  138. // Can call D_PostEvent.
  139. //
  140. void I_StartFrame (void)
  141. {
  142.   amiga_getevents ();
  143. }
  144.  
  145. /**********************************************************************/
  146. //
  147. // Called by D_DoomLoop,
  148. // called before processing each tic in a frame.
  149. // Quick syncronous operations are performed here.
  150. // Can call D_PostEvent.
  151. void I_StartTic (void)
  152. {
  153. }
  154.  
  155. /**********************************************************************/
  156. // Asynchronous interrupt functions should maintain private queues
  157. // that are read by the synchronous functions
  158. // to be converted into events.
  159.  
  160. // Either returns a null ticcmd,
  161. // or calls a loadable driver to build it.
  162. // This ticcmd will then be modified by the gameloop
  163. // for normal input.
  164. ticcmd_t    emptycmd;
  165. ticcmd_t* I_BaseTiccmd (void)
  166. {
  167.   return &emptycmd;
  168. }
  169.  
  170. /**********************************************************************/
  171. // Called by M_Responder when quit is selected.
  172. // Clean exit, displays sell blurb.
  173. void I_Quit (void)
  174. {
  175.   D_QuitNetGame ();
  176.   I_ShutdownSound();
  177.   I_ShutdownMusic();
  178.   M_SaveDefaults ();
  179.   I_ShutdownGraphics();
  180.  
  181.   if (GfxBase != NULL) {
  182.     CloseLibrary ((struct Library *) GfxBase);
  183.     GfxBase = NULL;
  184.   }
  185.   if (IntuitionBase != NULL) {
  186.     CloseLibrary ((struct Library *) IntuitionBase);
  187.     IntuitionBase = NULL;
  188.   }
  189.  
  190.   if (vid_mem != NULL)
  191. #ifdef WARPUP
  192.         FreeVecPPC (vid_mem);
  193. #elif defined(MORPHOS)
  194.         FreeVec (vid_mem);
  195. #else
  196.     PPCFreeVec (vid_mem);
  197. #endif
  198.  
  199. //    if (UtilityBase != NULL) {
  200. //        CloseLibrary(UtilityBase);
  201. //        UtilityBase = NULL;
  202. //    }
  203.  
  204.   exit(0);
  205. }
  206.  
  207. /**********************************************************************/
  208. // Allocates from low memory under dos,
  209. // just mallocs under unix
  210. byte* I_AllocLow (int length)
  211. {
  212.   byte*    mem;
  213.  
  214.   if ((mem = (byte *)malloc (length)) == NULL)
  215.     I_Error ("Out of memory allocating %d bytes", length);
  216.   memset (mem,0,length);
  217.   return mem;
  218. }
  219.  
  220. /**********************************************************************/
  221. void I_Tactile (int on, int off, int total)
  222. {
  223.   // UNUSED.
  224.   on = off = total = 0;
  225. }
  226.  
  227. /**********************************************************************/
  228. void *I_malloc (size_t size)
  229. {
  230.   void *b;
  231.  
  232.   if ((b = malloc (size)) == NULL)
  233.     I_Error ("Out of memory allocating %d bytes", size);
  234.   return b;
  235. }
  236.  
  237. /**********************************************************************/
  238. void *I_calloc (size_t nelt, size_t esize)
  239. {
  240.   void *b;
  241.  
  242.   if ((b = calloc (nelt, esize)) == NULL)
  243.     I_Error ("Out of memory allocating %d bytes", nelt * esize);
  244.   return b;
  245. }
  246.  
  247. /**********************************************************************/
  248. void I_Error (char *error, ...)
  249. {
  250.   va_list    argptr;
  251.  
  252.   // Message first.
  253.   va_start (argptr, error);
  254.   fprintf (stderr, "Error: ");
  255.   vfprintf (stderr, error, argptr);
  256.   fprintf (stderr, "\n");
  257.   va_end (argptr);
  258.  
  259.   fflush (stderr);
  260.  
  261.   // Shutdown. Here might be other errors.
  262.   if (demorecording)
  263.     G_CheckDemoStatus ();
  264.  
  265.   D_QuitNetGame ();
  266.   I_ShutdownGraphics ();
  267.  
  268.   if (GfxBase != NULL) {
  269.     CloseLibrary ((struct Library *) GfxBase);
  270.     GfxBase = NULL;
  271.   }
  272.   if (IntuitionBase != NULL) {
  273.     CloseLibrary ((struct Library *) IntuitionBase);
  274.     IntuitionBase = NULL;
  275.   }
  276.  
  277.   if (vid_mem != NULL)
  278. #ifdef WARPUP
  279.         FreeVecPPC (vid_mem);
  280. #elif defined(MORPHOS)
  281.         FreeVec (vid_mem);
  282. #else
  283.     PPCFreeVec (vid_mem);
  284. #endif
  285.  
  286. //    if (UtilityBase != NULL) {
  287. //        CloseLibrary(UtilityBase);
  288. //        UtilityBase = NULL;
  289. //    }
  290.  
  291.   exit (20);
  292. }
  293.  
  294. /**********************************************************************/
  295. #ifdef __VBCC__
  296. #undef MAXINT
  297. #undef MININT
  298. #include <dos/dos.h>
  299. #include <proto/dos.h>
  300. #include <extra.h>
  301.  
  302. int strcasecmp(const char *str1, const char *str2)
  303. {
  304.     return stricmp(str1, str2);
  305. }
  306.  
  307. int strncasecmp(const char *str1, const char *str2, size_t n)
  308. {
  309.     return strnicmp(str1, str2, n);
  310. }
  311.  
  312. void *realloc(void *ptr,size_t size)
  313. {
  314.   void *a;
  315.   size_t l;
  316.   if(size)
  317.     a=malloc(size);
  318.   else
  319.     a=NULL;
  320.   if(ptr!=NULL)
  321.   { if(a!=NULL)
  322.     { l=((ULONG *)ptr)[-1]-sizeof(ULONG);
  323.       l=l<size?l:size;
  324.       CopyMemPPC(ptr,a,l);
  325.     }
  326.     if(size==0||a!=NULL)
  327.       free(ptr);
  328.   }
  329.   return a;
  330. }
  331.  
  332. int access(const char *path, int mode)
  333. {
  334.     BPTR lock;
  335.  
  336.     if ((lock = Lock((STRPTR) path, ACCESS_READ))) {
  337.         UnLock(lock);
  338.         return 0;
  339.     }
  340.  
  341.     return -1;
  342. }
  343. #endif
  344.